In [ ]:
%run "../Functions/0.1 GF English localization.ipynb"
http://localhost:8888/notebooks/v1.52.2/Functions/0.1%20GF%20English%20localization.ipynb
In [ ]:
processGFormFR = not ('gformFR1522' in globals())
if processGFormFR:
try:
gformFR1522 = pd.read_csv(\
frPath,\
dtype=str,\
parse_dates=['Timestamp'],\
date_parser=dateparseGForm,\
)
print("gformFR read_csv success")
except FileNotFoundError:
print("gformFR read_csv failed")
In [ ]:
if processGFormFR:
gformFR1522['Language'] = pd.Series(frLanguageID, index=gformFR1522.index)
In [ ]:
if processGFormFR:
gformFR1522['Temporality'] = pd.Series(answerTemporalities[2], index=gformFR1522.index)
In [ ]:
if processGFormFR:
questionsAnswersTranslationsFR = pd.read_csv(frTranslationsPath)
questionsAnswersTranslationsFR.index = questionsAnswersTranslationsFR[questionsAnswersTranslationsFR.columns[0]].values
questionsAnswersTranslationsFR = questionsAnswersTranslationsFR.T.iloc[1]
questionsAnswersTranslationsFR = pd.Series([[]],index = list(['Timestamp'])).append(questionsAnswersTranslationsFR)
In [ ]:
if processGFormFR:
replacementToken = '$$$$'
def replaceInWords(word, _replacement = ''):
return '"' + word.group(1) + word.group(2) + _replacement + "'" + word.group(3) + word.group(4) + '"'
def prepareForDictJsonLoading(input_string):
# replace in-words \' by $$$$'
#print(input_string)
previous = ''
while(previous != input_string):
previous = input_string
input_string = re.sub('"(.*)(\w+)\'(\w+)(.*)"', lambda w: replaceInWords(w, _replacement=replacementToken), input_string, re.UNICODE)
#print(input_string)
# replace all \' by \"
input_string = input_string.replace("'", '"')
#print(input_string)
# replace back in-words $$$$\" to \'
#input_string = re.sub('"(.*)(\w+)$$$$"(\w+)(.*)"', lambda w: replaceInWords(w, _replacement = '@'), input_string, re.UNICODE)
previous = ''
while(previous != input_string):
previous = input_string
input_string = input_string.replace(replacementToken + '"', '\'')
return input_string
def string_to_dict(dict_string):
#print("loading " + dict_string)
return json.loads(dict_string)
In [ ]:
#questionsAnswersTranslationsFR.loc['Do you play video games?']
In [ ]:
#string_to_dict(prepareForDictJsonLoading(questionsAnswersTranslationsFR.loc['Do you play video games?']))
In [ ]:
if processGFormFR:
for label in questionsAnswersTranslationsFR.index:
#print(label)
val = questionsAnswersTranslationsFR.loc[label]
if(type(val) is str):
_dict = string_to_dict(prepareForDictJsonLoading(val))
#print(val)
#print(_dict)
questionsAnswersTranslationsFR.loc[label] = [_dict]
In [ ]:
#correctAnswersFR = pd.read_csv(frCorrectScientificAnswersPath)
In [ ]:
#demographicAnswersFR = pd.read_csv(frDemographicAnswersPath)